package cn.itsource.config;

import cn.itsource.filter.RequestTimeFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    //配置Filter作用于那个访问规则上
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {

        return builder.routes().route(r -> r.path("/pay/**")
                //去掉2个前缀
                        .filters(f -> f.stripPrefix(1)
                        .filter(new RequestTimeFilter()))
                        .uri("lb://pay-server")
                        .order(0)
                        .id("test-RequestTimeFilter")
                ).build();
    }

    /**
     *         - id : application-user #指定服务名
     *           uri: lb://user-server #去注册中心找这个服务名
     *           predicates:    #断言，匹配访问的路径
     *             - Path=/user/**	#服务访问路径 #
     *           # http://localhost:6001/user/user/getUserById/2
     *           filters:
     *             - StripPrefix=1	#请求转发的时候会去掉 /user访问路径
     */
}
